![]() |
PATH![]() |
![]() ![]() |
User-defined commands are commands that trigger the execution of collections of statements, called subroutines, elsewhere in the same script. The target of a user-defined command is the current script, that is, the script from which the command is executed.
There are two ways to specify the current script as the target of a user-defined command. Outside of a Tell statement, simply use the command to specify the current script as its target. For example, suppose that minimumValue is a command defined by the user in the current script. The handler for the minimumValue command is a subroutine that returns the smaller of two values. The target of the minimumValue command in the following example is the current script:
set theCount to minimumValue(12,105)
Inside a Tell statement, use the words of , me , or my to indicate that the target of the command is the current script and not the default target of the Tell statement. For example, the following sample script shows how to call the minimumValue subroutine from within a Tell statement:
tell application "Finder"
set fileCount to count files in front window
set myCount to my minimumValue(fileCount, 100)
--do something with up to the first 100 files...
end tell
Without the word my before the minimumValue command, AppleScript would send the minimumValue command to the Finder, resulting in an error.
Handlers describes the syntax for defining and invoking subroutines such as minimumValue in more detail.
Note
You can also define subroutines in script objects. The target of a user-defined command whose subroutine is defined in a script object is the script object. For information about defining and invoking subroutines in script objects, see Script Objects.